#include <iostream>
using namespace std;

const int N = 1e6 + 10;

int n,heap[N];

void up(int chi){
	int par = chi / 2;
	while(chi >= 1){
		if(heap[par] < heap[chi] && par >= 1)
			swap(heap[par],heap[chi]);
			chi = par;
			par = chi / 2;
	} 
}

void down(int par){
	int chi = par * 2;
	while(chi <= n){
		if(chi + 1 <= n && heap[chi + 1] > heap[chi]) chi++;
		if(heap[par] >= heap[chi]) return ;
		swap(heap[chi],heap[par]);
		par = chi;
		chi = par * 2;
	}
}

void push(int x){
	heap[++n] = x;
	up(n);
}

void pop(){
	swap(heap[1],heap[n--]);
	down(1);
}

int top(){
	return heap[1];
}

int size(){
	return n;
}

int main(){
	int a[10] = {1, 41, 23, 10, 11, 2, -1, 99, 14, 0};
	for(int i = 0;i < 10;i++){
		push(a[i]);
	}
	while(size()){
		cout << top() << " ";
		pop();
	}
	return 0;
}
